Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
Los botones "Ctrl+A" y "del" no funcionan con el campo de entrada de validación de ssn

En este jsfiddle, si intenta ingresar algunos números en el campo de entrada, intente "ctrl + A" y elimine lo que ingresó, O intente usar el botón "del" (eliminar), el comportamiento esperado para eliminar el contenido no se produce. ¿Alguna idea de por qué? Siento que necesito decirle al valor de expresión regular en el método replace () que no incluya "ctrl" (o comando en una Mac) o "del", pero no estoy seguro de cómo implementarlo.

jsfiddle: http://jsfiddle.net/eujzh10n/2/

 <div id="u22" class="ax_text_field"> <input id="u22_input" class="ssn" type="text" value="" data-label="ssn1" maxlength="11"/> </div>
 // SSN validation // trap keypress - only allow numbers $('input.ssn').on('keypress', function(event){ // trap keypress var character = String.fromCharCode(event.which); if(!isInteger(character)){ return false; } }); // checks that an input string is an integer, with an optional +/- sign character function isInteger (s) { if(s === '-') return true; var isInteger_re = /^\s*(\+|-)?\d+\s*$/; return String(s).search (isInteger_re) != -1 } // format SSN $('input.ssn').on('keyup', function(){ var val = this.value.replace(/\D/g, ''); var newVal = ''; if(val.length > 4) { this.value = val; } if((val.length > 3) && (val.length < 6)) { newVal += val.substr(0, 3) + '-'; val = val.substr(3); } if (val.length > 5) { newVal += val.substr(0, 3) + '-'; newVal += val.substr(3, 2) + '-'; val = val.substr(5); } newVal += val; this.value = newVal; });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

En su controlador de teclado, solo reemplace la entrada si el valor ha cambiado (lo que no ocurre con Ctrl-A, etc.)

 // SSN validation // trap keypress - only allow numbers $('input.ssn').on('keypress', function(event){ // trap keypress var character = String.fromCharCode(event.which); if(!isInteger(character)){ return false; } }); // checks that an input string is an integer, with an optional +/- sign character function isInteger (s) { if(s === '-') return true; var isInteger_re = /^\s*(\+|-)?\d+\s*$/; return String(s).search (isInteger_re) != -1 } // format SSN $('input.ssn').on('keyup', function(){ var val = this.value.replace(/\D/g, ''); var newVal = ''; // I'm not sure what this is for, but it updates the field perhaps unnecessarily // if(val.length > 4) { // this.value = val; // } if((val.length > 3) && (val.length < 6)) { newVal += val.substr(0, 3) + '-'; val = val.substr(3); } if (val.length > 5) { newVal += val.substr(0, 3) + '-'; newVal += val.substr(3, 2) + '-'; val = val.substr(5); } newVal += val; if (this.value != newVal) { // only update the field if its content has changed this.value = newVal; } });
 input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { /* display: none; <- Crashes Chrome on hover */ -webkit-appearance: none; margin: 0; /* <-- Apparently some margin are still there even though it's hidden */ } .error-border { border: 2px solid #dadada; border-radius: 7px; } .error-border:focus { outline: none; border-color: #F00; box-shadow: 0 0 10px #F00; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="u22" class="ax_text_field"> <input id="u22_input" class="ssn" type="text" value="" data-label="ssn1" maxlength="11"/> </div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda